<?php
//主体类
class Originator{
    public $state;

    public function createMemento(){
        return new Memento($this->state);
    }

    public function setMemento($memento){
        $this->state = $memento->state;
    }

    public function show(){
        echo $this->state;
    }
}
//备忘录类
class Memento{
    public $state;
    public function __construct($state)
    {
        $this->state = $state;
    }
}

//管理者
class Caretaker{
    public $memento;
}

//客户端
$originator = new Originator();
$originator->state = 'on';
$originator->show();

$caretaker = new Caretaker();
$caretaker->memento = $originator->createMemento();
$originator->state = 'off';
$originator->show();


$originator->setMemento($caretaker->memento);
$originator->show();


